home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianJohnFiles.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  32KB  |  1,203 lines

  1. #include "Scian.h"
  2. #include "ScianTypes.h"
  3. #include "ScianIDs.h"
  4. #include "ScianLists.h"
  5. #include "ScianColors.h"
  6. #include "ScianErrors.h"
  7. #include "ScianNames.h"
  8. #include "ScianGarbageMan.h"
  9. #include "ScianMethods.h"
  10. #include "ScianArrays.h"
  11. #include "ScianTimers.h"
  12. #include "ScianPictures.h"
  13. #include "ScianWindows.h"
  14. #include "ScianVisWindows.h"
  15. #include "ScianDialogs.h"
  16. #include "ScianComplexControls.h"
  17. #include "ScianDatasets.h"
  18. #include "ScianVisObjects.h"
  19. #include "ScianFiles.h"
  20.  
  21. #define MAX3(x,y,z) (MAX(MAX(x,y),z))
  22. #define MIN3(x,y,z) (MIN(MIN(x,y),z))
  23.  
  24. #define MAXLINE 1024
  25.  
  26. #define NUMDIMS 4
  27. #define DIM1 16
  28. #define DIM2 16
  29. #define DIM3 16
  30. #define DIM4 16
  31. #define NUMARRAYS 20
  32. #define ARRAYSIZE (DIM1*DIM2*DIM3*DIM4)
  33.  
  34. #ifdef PROTO
  35. char *ShortNameOf(char *n);
  36. #else
  37. char *ShortNameOf();
  38. #endif
  39.  
  40. extern ObjPtr data3DScalar;
  41.  
  42. #define FTNREALS 0
  43. #if FTNREALS
  44. #define FTNGARBAGE 0x00000400L
  45. #else
  46. #define FTNGARBAGE 0x00000400L
  47. #endif
  48.  
  49. #define FTNMIN -30000
  50. #define FTNMAX 30000
  51.  
  52. static ObjPtr ReadGBCFile(name)
  53. char *name;
  54. /*Reads one of bali's binary files*/
  55. {
  56.     ObjPtr timeSteps;
  57.     ObjPtr timedObj;
  58.     FILE *inFile;
  59.     long whichFrame;
  60.     real dims[3];            /*The dimensions of the data, temp.*/
  61.     real bounds[6];            /*The bounds of the data form*/
  62.     long xSize, ySize;
  63.     long dataSize;            /*Dummy to hold size of data*/
  64.     real dataMin, dataMax;
  65.     ObjPtr dataForm;
  66.     ObjPtr dimsArray, boundsArray;
  67.     long nFrames;
  68.     int numRead;        /* number of elements successfully fread */
  69.     int i, j, k, l, tmp;
  70.     real bigArray[DIM1][DIM2][DIM3][DIM4];
  71.     ObjPtr timeDatas[DIM1];
  72.     int junk[5];
  73.     unsigned int foo;
  74.     ObjPtr minMaxArray;
  75.     real minMax[2];
  76.  
  77.     inFile = fopen(name, "r");
  78.     if (!inFile)
  79.     {
  80.     Error("ReadGBCFile", OPENFILEERROR, name);
  81.     return NULLOBJ;
  82.     }
  83.  
  84.     /* set up data lists for array parts to be shoveled into */
  85.     for (i = 0; i < DIM1; ++i)
  86.     {
  87.     timeDatas[i] = NewList();
  88.     }
  89.  
  90.     whichFrame = 0;
  91.     /* using the brute force method, since all dimensions are equal length */
  92.     while (ARRAYSIZE == (numRead = fread(bigArray, sizeof(real), ARRAYSIZE, inFile)))
  93.     {
  94.     for (i=0; i<DIM1; ++i)
  95.     {
  96.         ObjPtr timeThing;
  97.  
  98.         timeThing = NewRealArray(NUMDIMS - 1, (long) DIM2,
  99.                      (long) DIM3, (long) DIM4);
  100.         CArray2Array(timeThing, bigArray[i]);
  101.         PostfixList(timeDatas[i], timeThing);
  102.     }
  103.     ++whichFrame;
  104.     }
  105.  
  106.     fclose(inFile);
  107.  
  108.     timeSteps = NewList();
  109.     for (i = 0; i < whichFrame; ++i)
  110.     {
  111.     PostfixList(timeSteps, NewReal(i));
  112.     }
  113.  
  114.     /*Create the data form*/
  115.     dataForm = NewObject(dataFormClass, 0);
  116.     dimsArray = NewRealArray(1, (long) 3);
  117.     
  118.     /*Put in some dimensions*/
  119.     dims[0] = (real) DIM2;
  120.     dims[1] = (real) DIM3;
  121.     dims[2] = (real) DIM4;
  122.     CArray2Array(dimsArray, dims);
  123.     SetVar(dataForm, DIMENSIONS, dimsArray); 
  124.     boundsArray = NewRealArray(1, 6L);
  125.     bounds[0] = bounds[2] = bounds[4] = 0.0;
  126.     bounds[1] = DIM2;
  127.     bounds[3] = DIM3;
  128.     bounds[5] = DIM4;
  129.     CArray2Array(boundsArray, bounds);
  130.     SetVar(dataForm, BOUNDS, boundsArray);
  131.  
  132.     minMax[0] = FTNMIN;
  133.     minMax[1] = FTNMAX;
  134.                 minMaxArray = NewRealArray(1, 2L);
  135.                     CArray2Array(minMaxArray, minMax);
  136.  
  137.     for (i=0; i<DIM1; ++i)
  138.     {
  139.     ObjPtr dataThing;
  140.  
  141.     dataThing = NewObject(data3DScalar, 0);
  142.     SetVar(dataThing, DATA, NewTimedObject(timeSteps, timeDatas[i]));
  143.     SetVar(dataThing, DATAFORM, dataForm);
  144.     sprintf(tempStr, "%s%d", ShortNameOf(name), i);
  145.     SetVar(dataThing, NAME, NewString(tempStr));
  146.         SetVar(dataThing, MINMAX, minMaxArray);
  147.  
  148.     RegisterDataset(dataThing);
  149.     }
  150.  
  151.     return NULLOBJ;
  152. }
  153.  
  154. static ObjPtr ReadGBC2File(name)
  155. char *name;
  156. /*Reads one of bali's binary files, only this time Scian time is across the
  157.  * major spatial dimension
  158.  */
  159. {
  160.     ObjPtr timeSteps;
  161.     ObjPtr timedObj;
  162.     FILE *inFile;
  163.     long whichFrame;
  164.     real dims[3];            /*The dimensions of the data, temp.*/
  165.     real bounds[6];            /*The bounds of the data form*/
  166.     long xSize, ySize;
  167.     long dataSize;            /*Dummy to hold size of data*/
  168.     real dataMin, dataMax;
  169.     ObjPtr dataForm;
  170.     ObjPtr dimsArray, boundsArray;
  171.     ObjPtr retVal;
  172.     long nFrames;
  173.     int numRead;        /* number of elements successfully fread */
  174.     int i, j, k, l, tmp;
  175.     real bigArray[DIM1][DIM2][DIM3][DIM4];
  176.     long junk[2];
  177.     unsigned int foo;
  178.     ObjPtr minMaxArray;
  179.     real minMax[2];
  180.  
  181.     inFile = fopen(name, "r");
  182.     if (!inFile)
  183.     {
  184.     Error("ReadGBC2File", OPENFILEERROR, name);
  185.     return NULLOBJ;
  186.     }
  187.  
  188.     /* setting up stuff for the objects created in the loop */
  189.     retVal = NewList();
  190.     minMax[0] = FTNMIN;
  191.     minMax[1] = FTNMAX;
  192.     minMaxArray = NewRealArray(1, 2L);
  193.     CArray2Array(minMaxArray, minMax);
  194.  
  195.     /*Create the data form */
  196.     dataForm = NewObject(dataFormClass, 0);
  197.     dimsArray = NewRealArray(1, (long) 3);
  198.     
  199.     /* Put in some dimensions and bounds */
  200.     dims[0] = (real) DIM2;
  201.     dims[1] = (real) DIM3;
  202.     dims[2] = (real) DIM4;
  203.     CArray2Array(dimsArray, dims);
  204.     SetVar(dataForm, DIMENSIONS, dimsArray); 
  205.     boundsArray = NewRealArray(1, 6L);
  206.     bounds[0] = bounds[2] = bounds[4] = 0.0;
  207.     bounds[1] = DIM2;
  208.     bounds[3] = DIM3;
  209.     bounds[5] = DIM4;
  210.     CArray2Array(boundsArray, bounds);
  211.     SetVar(dataForm, BOUNDS, boundsArray);
  212.  
  213.     timeSteps = NewList();
  214.     for (i = 0; i < DIM1; ++i)
  215.     {
  216.     PostfixList(timeSteps, NewReal(i));
  217.     }
  218.  
  219.     whichFrame = 0;
  220.     /* using the brute force method, since all dimensions are equal length */
  221.     while (ARRAYSIZE == (numRead = fread(bigArray, sizeof(real), ARRAYSIZE, inFile)))
  222.     {
  223.     ObjPtr retThing, timeData;
  224.  
  225.     retThing = NewObject(data3DScalar, 0);
  226.     timeData = NewList();
  227.  
  228.     for (i=0; i<DIM1; ++i)
  229.     {
  230.         ObjPtr timeThing;
  231.  
  232.         timeThing = NewRealArray(NUMDIMS - 1, (long) DIM2,
  233.                      (long) DIM3, (long) DIM4);
  234.         CArray2Array(timeThing, bigArray[i]);
  235.         PostfixList(timeData, timeThing);
  236.     }
  237.  
  238.     SetVar(retThing, DATA, NewTimedObject(timeSteps, timeData));
  239.     SetVar(retThing, DATAFORM, dataForm);
  240.     sprintf(tempStr, "%s%d", ShortNameOf(name), whichFrame);
  241.     SetVar(retThing, NAME, NewString(tempStr));
  242.         SetVar(retThing, MINMAX, minMaxArray);
  243.  
  244.     RegisterDataset(retThing);
  245.  
  246.     ++whichFrame;
  247.     }
  248.  
  249.     fclose(inFile);
  250.  
  251.     return NULLOBJ;
  252. }
  253.  
  254. #define SSDIM1 4
  255. #define SSDIM2 10
  256. #define SSDIM3 10
  257. #define SSDIM4 10
  258. #define SSNUMARRAYS 200
  259. #define SSNUMDIMS 4
  260. #define SSARRAYSIZE (SSDIM1*SSDIM2*SSDIM3*SSDIM4)
  261.  
  262. static ObjPtr ReadSSFile(name)
  263. char *name;
  264. /*Reads one of sergiu's binary files*/
  265. {
  266.     ObjPtr timeSteps;
  267.     ObjPtr timedObj;
  268.     FILE *inFile;
  269.     long whichFrame;
  270.     real dims[3];            /*The dimensions of the data, temp.*/
  271.     real bounds[6];            /*The bounds of the data form*/
  272.     long xSize, ySize;
  273.     long dataSize;            /*Dummy to hold size of data*/
  274.     real dataMin, dataMax;
  275.     ObjPtr dataForm;
  276.     ObjPtr dimsArray, boundsArray;
  277.     long nFrames;
  278.     int numRead;        /* number of elements successfully fread */
  279.     int i, j, k, l, tmp;
  280.     real bigArray[SSDIM1][SSDIM2][SSDIM3][SSDIM4];
  281.     ObjPtr timeDatas[SSDIM1];
  282.     int junk[5];
  283.     unsigned int foo;
  284.     ObjPtr minMaxArray;
  285.     real minMax[2];
  286.  
  287.     inFile = fopen(name, "r");
  288.     if (!inFile)
  289.     {
  290.     Error("ReadSSFile", OPENFILEERROR, name);
  291.     return NULLOBJ;
  292.     }
  293.  
  294.     /* set up data lists for array parts to be shoveled into */
  295.     for (i = 0; i < SSDIM1; ++i)
  296.     {
  297.     timeDatas[i] = NewList();
  298.     }
  299.  
  300.     whichFrame = 0;
  301.     /* using the brute force method, since all dimensions are equal length */
  302.     while (SSARRAYSIZE == (numRead = fread(bigArray, sizeof(real), SSARRAYSIZE, inFile)))
  303.     {
  304.     for (i=0; i<SSDIM1; ++i)
  305.     {
  306.         ObjPtr timeThing;
  307.  
  308.         timeThing = NewRealArray(SSNUMDIMS - 1, (long) SSDIM2,
  309.                      (long) SSDIM3, (long) SSDIM4);
  310.         CArray2Array(timeThing, bigArray[i]);
  311.         PostfixList(timeDatas[i], timeThing);
  312.     }
  313.     ++whichFrame;
  314.     }
  315.  
  316.     fclose(inFile);
  317.  
  318.     timeSteps = NewList();
  319.     for (i = 0; i < whichFrame; ++i)
  320.     {
  321.     PostfixList(timeSteps, NewReal(i));
  322.     }
  323.  
  324.     /*Create the data form*/
  325.     dataForm = NewObject(dataFormClass, 0);
  326.     dimsArray = NewRealArray(1, (long) 3);
  327.     
  328.     /*Put in some dimensions*/
  329.     dims[0] = (real) SSDIM2;
  330.     dims[1] = (real) SSDIM3;
  331.     dims[2] = (real) SSDIM4;
  332.     CArray2Array(dimsArray, dims);
  333.     SetVar(dataForm, DIMENSIONS, dimsArray); 
  334.     boundsArray = NewRealArray(1, 6L);
  335.     bounds[0] = bounds[2] = bounds[4] = 0.0;
  336.     bounds[1] = SSDIM2;
  337.     bounds[3] = SSDIM3;
  338.     bounds[5] = SSDIM4;
  339.     CArray2Array(boundsArray, bounds);
  340.     SetVar(dataForm, BOUNDS, boundsArray);
  341.  
  342.     minMax[0] = -25;
  343.     minMax[1] = 25;
  344.     minMaxArray = NewRealArray(1, 2L);
  345.     CArray2Array(minMaxArray, minMax);
  346.  
  347.     for (i=0; i<SSDIM1; ++i)
  348.     {
  349.     ObjPtr retThing;
  350.  
  351.     retThing = NewObject(data3DScalar, 0);
  352.     SetVar(retThing, DATA, NewTimedObject(timeSteps, timeDatas[i]));
  353.     SetVar(retThing, DATAFORM, dataForm);
  354.     sprintf(tempStr, "%s%d", ShortNameOf(name), i);
  355.     SetVar(retThing, NAME, NewString(tempStr));
  356.         SetVar(retThing, MINMAX, minMaxArray);
  357.  
  358.     RegisterDataset(retThing);
  359.     }
  360.  
  361.     return NULLOBJ;
  362. }
  363.  
  364. /* maximum number of atoms in one molecule file */
  365. #define NATOMS 1024
  366. /* maximum atomic number of a single atom */
  367. #define MAXWT 256
  368.  
  369. #define G90_SPHERE_SCALE 0.7
  370. /* #define G90_SUBDIVIDE_CYLINDERS 5 */
  371.  
  372. static ObjPtr ReadG90File(name)
  373. char *name;
  374. /*Reads one kind of gaussian output file*/
  375. {
  376.     FILE *inFile, *conFile;        /* inFile is the real data, conFile is the connection file*/
  377.     real dims[3];            /*The dimensions of the data, temp.*/
  378.     real bounds[6];            /*The bounds of the data form*/
  379.     ObjPtr dataForm;
  380.     ObjPtr dimsArray, boundsArray;
  381.     ObjPtr retField, retList, retPicture; /*the things that get returned */
  382.     ObjPtr fieldData;    /* the actual data of the field */
  383.     ObjPtr picture, picArray[MAXWT];    /* contains the NFF objects representing atoms*/
  384.     int i, j, k, l, tmp;
  385.     Bool notdone;
  386.     real xScale, yScale, zScale;
  387.     real xLoc, yLoc, zLoc;
  388.     real rot[3][3];
  389.     int idummy;
  390.     int nAtoms = 0, n1 = 0, n2 = 0, n3 = 0; /* yeah, just 'cause I'm paranoid doesn't mean the compiler isn't out to get me! */
  391.     real *dataPtr;
  392.     real origin[3];
  393.     float center[NATOMS][3];
  394.     real stickRad = PLUSINF;
  395.     real dataAverage;        /* running average of the data */
  396.     int dataCount;        /* running count of number of data items */
  397.     int titleLines;        /* count of number of title lines */
  398.  
  399.     inFile = fopen(name, "r");
  400.     if (!inFile)
  401.     {
  402.     Error("ReadG90File", OPENFILEERROR, name);
  403.     return NULLOBJ;
  404.     }
  405.  
  406.     /* read the header information */
  407.     titleLines = 0;
  408.     while (4 != fscanf(inFile, "%d %f %f %f\n", &nAtoms,
  409.             &origin[0], &origin[1], &origin[2]))
  410.     {
  411.     fgets(tempStr, TEMPSTRSIZE, inFile);
  412.     ++titleLines;
  413.     if (feof(inFile))
  414.     {
  415.         fprintf(stderr, "error reading datafile %s\n", name);
  416.         return NULLOBJ;
  417.     }
  418.     }
  419.     if (titleLines)
  420.     fprintf(stderr, "assuming %d title lines before real data\n", titleLines);
  421.  
  422.     if (4 != fscanf(inFile, "%d %f %f %f\n", &n1,&rot[0][0],&rot[1][0],&rot[2][0]))
  423.     {
  424.     ReportError("ReadG90file", "error reading header line 2");
  425.     }
  426.     if (4 != fscanf(inFile, "%d %f %f %f\n", &n2,&rot[0][1],&rot[1][1],&rot[2][1]))
  427.     {
  428.     ReportError("ReadG90file", "error reading header line 3");
  429.     }
  430.     if (4 != fscanf(inFile, "%d %f %f %f\n", &n3,&rot[0][2],&rot[1][2],&rot[2][2]))
  431.     {
  432.     ReportError("ReadG90file", "error reading header line 4");
  433.     }
  434.  
  435.     xScale = sqrt(rot[0][0]*rot[0][0]+rot[1][0]*rot[1][0]+rot[2][0]*rot[2][0]);
  436.     yScale = sqrt(rot[0][1]*rot[0][1]+rot[1][1]*rot[1][1]+rot[2][1]*rot[2][1]);
  437.     zScale = sqrt(rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]+rot[2][2]*rot[2][2]);
  438.  
  439. #if 0
  440. #define SCALE 100
  441.  
  442.     xScale /= SCALE;
  443.     yScale /= SCALE;
  444.     zScale /= SCALE;
  445. #endif
  446.  
  447.     /* create new Pictures for the blobs representing the atoms */
  448. #if 0
  449.     for (i = 0; i < MAXWT; ++i)
  450.     {
  451.     picArray[i] = NULLOBJ;
  452.     }
  453. #else
  454.     picArray[0] = NULLOBJ;
  455. #endif
  456.  
  457.     if (nAtoms >= NATOMS)
  458.     {
  459.     sprintf(tempStr, "number of atoms, %d, exceeds maximum, %d", nAtoms, NATOMS-1);
  460.     ReportError("ReadG90File", tempStr);
  461.     return NULLOBJ;
  462.     }
  463.  
  464.     /* read the atom position data */
  465.     for (i = 0; i < nAtoms; ++i)
  466.     {
  467.     unsigned int atomicNum;
  468.     float atomicCharge;
  469.     float atomRad;
  470.  
  471.     if (5 != fscanf(inFile, "%d %f %f %f %f\n", &atomicNum, &atomicCharge,
  472.                 &xLoc, &yLoc, &zLoc))
  473.     {
  474.         sprintf(tempStr, "error reading atom %d\n", i);
  475.         ReportError("ReadG90file", tempStr);
  476.     }
  477.     /* this could all be done in a transformation matrix, but oh well.. */
  478.     center[i][0] = xLoc * rot[0][0] + yLoc * rot[1][0] + zLoc * rot[2][0];
  479.     center[i][1] = xLoc * rot[0][1] + yLoc * rot[1][1] + zLoc * rot[2][1];
  480.     center[i][2] = xLoc * rot[0][2] + yLoc * rot[1][2] + zLoc * rot[2][2];
  481.     center[i][0] /= xScale;
  482.     center[i][1] /= yScale;
  483.     center[i][2] /= zScale;
  484.     /* size of atom is proportional to sqrt(atomicNumber + C) */
  485. /*
  486.     fprintf(stderr, "loc was %f, %f, %f, transformed to %f, %f, %f. atomicNum %d, scaled to %f\n",
  487.         xLoc, yLoc, zLoc, center[i][0], center[i][1], center[i][2],
  488.         atomicNum, cbrt(atomicNum));
  489. */
  490.     if (atomicNum >= MAXWT)
  491.     {
  492.         ReportError("ReadG90file", "atomic number exceeded maximum");
  493.         atomicNum = 1;
  494.     }
  495.  
  496. #if 0
  497.     if (!picArray[atomicNum])
  498.         picArray[atomicNum] = NewPicture();
  499.  
  500.     atomRad = G90_SPHERE_SCALE * cbrt(atomicNum) * MAX3(xScale, yScale, zScale);
  501.     AppendSphereToPicture(picArray[atomicNum], center[i], atomRad, atomicNum - 1);
  502.     stickRad = stickRad < atomRad ? stickRad : atomRad;
  503. #else
  504.     if (!picArray[0])
  505.         picArray[0] = NewPicture();
  506.  
  507.     atomRad = G90_SPHERE_SCALE * cbrt(atomicNum) * MAX3(xScale, yScale, zScale);
  508.     AppendSphereToPicture(picArray[0], center[i], atomRad, atomicNum - 1);
  509.     stickRad = stickRad < atomRad ? stickRad : atomRad;
  510. #endif
  511.     }
  512.  
  513. #if 0
  514.     for (i = 0; i < MAXWT; ++i)
  515.     {
  516.     if (picArray[i])
  517.     {
  518.         ObjPtr tmpName;
  519.  
  520.         retPicture = NewObject(geometryClass,0);
  521.         SetVar(retPicture, DATA, picArray[i]);
  522.         SetVar(picArray[i], REPOBJ, retPicture);
  523.         tmpName = MakeDatasetName(name);
  524. #ifdef DEBUG
  525. fprintf(stderr, "tmpName = %s\n", GetString(tmpName));
  526. #endif
  527.         sprintf(tempStr, "%s-%d-%s", "atoms", i, GetString(tmpName));
  528. #ifdef DEBUG
  529. fprintf(stderr, "concocted name = %s\n", tempStr);
  530. #endif
  531.         SetVar(retPicture, NAME, NewString(tempStr));
  532.         SetVar(retPicture, UNITSNAME, NewString("Atomic number"));
  533.         SetVar(retPicture, COLORBYSELF, ObjTrue);
  534.         RegisterDataset(retPicture);
  535.     }
  536.     }
  537. #else
  538.     if (picArray[0])
  539.     {
  540.         ObjPtr tmpName;
  541.  
  542.         retPicture = NewObject(geometryClass,0);
  543.         SetVar(retPicture, DATA, picArray[0]);
  544.         SetVar(picArray[0], REPOBJ, retPicture);
  545.         tmpName = MakeDatasetName(name);
  546. #ifdef DEBUG
  547. fprintf(stderr, "tmpName = %s\n", GetString(tmpName));
  548. #endif
  549.         sprintf(tempStr, "%s-%d-%s", "atoms", i, GetString(tmpName));
  550. #ifdef DEBUG
  551. fprintf(stderr, "concocted name = %s\n", tempStr);
  552. #endif
  553.         SetVar(retPicture, NAME, NewString(tempStr));
  554.         SetVar(retPicture, UNITSNAME, NewString("Atomic number"));
  555. #if 1
  556.         SetVar(retPicture, COLORBYSELF, ObjTrue);
  557.         RegisterDataset(retPicture);
  558. #endif
  559.     }
  560. #endif
  561.  
  562.     /* create the data holder */
  563.     fieldData = NewRealArray(3, (long) n1, (long) n2, (long) n3);
  564.     dataPtr = ArrayMeat(fieldData);
  565.  
  566.     /* read the grid data */
  567.     dataAverage = 0.0;
  568.     dataCount = 0;
  569.     notdone = true;
  570.     for (i=0; i<n1 && notdone; ++i)
  571.     {
  572.     for (j=0; j<n2 && notdone; ++j)
  573.     {
  574.         for (k=0; k<n3 && notdone; ++k)
  575.         {
  576.         real curVal;
  577.         if (1 != fscanf(inFile, "%g", &curVal))
  578.         {
  579.             sprintf(tempStr, "error reading array element %d %d %d\n", n1, n2, n3);
  580.             ReportError("ReadG90File", tempStr);
  581.             notdone = false;
  582.         }
  583.         *(dataPtr + i * n2 * n3 + j * n3 + k) = curVal;
  584.         dataAverage = (dataAverage * dataCount + curVal) / (dataCount + 1);
  585.         ++dataCount;
  586.         }
  587.     }
  588.     }
  589.  
  590.     fprintf(stderr, "average data value is %f\n", dataAverage);
  591.  
  592.     fclose(inFile);
  593.  
  594.     /*Create the data form*/
  595.     dataForm = NewObject(dataFormClass, 0);
  596.     dimsArray = NewRealArray(1, (long) 3);
  597.     
  598.     /*Put in some dimensions*/
  599.     dims[0] = n1;
  600.     dims[1] = n2;
  601.     dims[2] = n3;
  602.     CArray2Array(dimsArray, dims);
  603.     SetVar(dataForm, DIMENSIONS, dimsArray); 
  604.  
  605.     /* bounds determined by dimension length+way axis is stretched/squashed */
  606.     boundsArray = NewRealArray(1, 6L);
  607.     bounds[0] = origin[0];
  608.     bounds[1] = xScale * n1 + origin[0];
  609.     bounds[2] = origin[1];
  610.     bounds[3] = yScale * n2 + origin[1];
  611.     bounds[4] = origin[2];
  612.     bounds[5] = zScale * n3 + origin[2];
  613.     CArray2Array(boundsArray, bounds);
  614.     SetVar(dataForm, BOUNDS, boundsArray);
  615.  
  616.     retField = NewObject(data3DScalar, 0);
  617.     SetVar(retField, DATA, fieldData);
  618.     SetVar(retField, DATAFORM, dataForm);
  619.     sprintf(tempStr, "%s-%s", "charge", ShortNameOf(name));
  620.     SetVar(retField, NAME, NewString(tempStr));
  621.  
  622.     RegisterDataset(retField);
  623.  
  624.     /* see if the connection file exists */
  625.     sprintf(tempStr, "%s.bond", name);
  626.     conFile = fopen(tempStr, "r");
  627.     if (!conFile)
  628.     {
  629.     printf("bonds file not found. Won't show molecular bonds\n");
  630. #if 1
  631. #else
  632.     SetVar(retPicture, COLORBYSELF, ObjTrue);
  633.     RegisterDataset(retPicture);
  634. #endif
  635.     return NULLOBJ;
  636.     }
  637.     /* stick radius == 1/2 the radius of the smallest atom */
  638.     stickRad /= 2.0;
  639.  
  640. #if 1
  641.     picture = NewPicture();
  642. #else
  643.     picture = retPicture;
  644. #endif
  645.  
  646.     while(true)
  647.     {
  648.     int at1, at2;
  649.  
  650.     if (2 != fscanf(conFile, "%d%d", &at1, &at2))
  651.         goto done;
  652.  
  653.     if (at1 > nAtoms || at1 <= 0 || at2 > nAtoms || at2 <= 0)
  654.     {
  655.         printf("atom number out of range in bonds. Some bonds not shown\n");
  656.     }
  657.     else
  658.     {
  659. #ifdef G90_SUBDIVIDE_CYLINDERS
  660.  
  661.         float from[3], to[3];
  662.  
  663.         for (j = 0; j < 3; ++j)
  664.         to[j] = center[at1-1][j];
  665.  
  666.         for(i = 1; i < G90_SUBDIVIDE_CYLINDERS + 1; ++i)
  667.         {        
  668.         for (j = 0; j < 3; ++j)
  669.         {
  670.             from[j] = to[j];
  671.             to[j] = center[at1-1][j] + i * ((center[at2-1][j]
  672.             - center[at1-1][j]) / G90_SUBDIVIDE_CYLINDERS);
  673.         }
  674.         AppendFrustumToPicture(picture, from, stickRad,
  675.                     to, stickRad, -2);
  676.         }
  677. #else
  678.         /* bonds colored as missing data */
  679.         AppendFrustumToPicture(picture, center[at1-1], stickRad,
  680.                         center[at2-1], stickRad, -2);
  681. #endif
  682.     }
  683.     }
  684. done:
  685. #if 1
  686.     retPicture = NewObject(geometryClass,0);
  687.     SetVar(retPicture, DATA, picture);
  688.     SetVar(picture, REPOBJ, retPicture);
  689.     sprintf(tempStr, "%s-%s", "bonds", ShortNameOf(name));
  690.     SetVar(retPicture, NAME, NewString(tempStr));
  691.     SetVar(retPicture, UNITSNAME, NewString("Atomic number"));
  692.     SetVar(retPicture, COLORBYSELF, ObjTrue);
  693.     RegisterDataset(retPicture);
  694. #else
  695.     SetVar(retPicture, DATA, picture);
  696.     SetVar(picture, REPOBJ, retPicture);
  697.     SetVar(retPicture, UNITSNAME, NewString("Atomic number"));
  698.     SetVar(retPicture, COLORBYSELF, ObjTrue);
  699.     RegisterDataset(retPicture);
  700. #endif
  701.  
  702.     return NULLOBJ;
  703. }
  704.  
  705. static ObjPtr ReadPBOLDFile(name)
  706. char *name;
  707. /*Reads one of bali's binary files*/
  708. {
  709.     FILE *inFile;
  710.     real dims[3];            /*The dimensions of the data, temp.*/
  711.     real bounds[6];            /*The bounds of the data form*/
  712.     ObjPtr dataForm;
  713.     ObjPtr dimsArray, boundsArray;
  714.     ObjPtr retField, retList, retPicture; /*the things that get returned */
  715.     ObjPtr fieldData;    /* the actual data of the field */
  716.     ObjPtr picture;    /* contains the NFF objects representing atoms*/
  717.     int i, j, k, l, tmp;
  718.     Bool notdone;
  719.     real rdummy, rdummy1, rdummy2;
  720.     real xScale, yScale, zScale;
  721.     real xLoc, yLoc, zLoc;
  722.     int idummy;
  723.     int nAtoms = 0, n1 = 0, n2 = 0, n3 = 0; /* yeah, just 'cause I'm paranoid doesn't mean the compiler isn't out to get me! */
  724.     real *dataPtr;
  725.     real origin[3];
  726.  
  727.     inFile = fopen(name, "r");
  728.     if (!inFile)
  729.     {
  730.     Error("ReadPBOLDFile", OPENFILEERROR, name);
  731.     return NULLOBJ;
  732.     }
  733.  
  734.     /* read the header information */
  735.     if (4 != fscanf(inFile, "%d %f %f %f\n", &nAtoms,
  736.             &origin[0], &origin[1], &origin[2]))
  737.     {
  738.     FileFormatError("ReadPBOLDfile", "error reading header line 1");
  739.     }
  740.  
  741.     /* HAK! */
  742.     rdummy1 = 0.0; rdummy2 = 0.0;
  743.     if (4 != fscanf(inFile, "%d %f %f %f\n", &n1,&xScale,&rdummy1,&rdummy2))
  744.     {
  745.     FileFormatError("ReadPBOLDfile", "error reading header line 2");
  746.     }
  747.     if (4 != fscanf(inFile, "%d %f %f %f\n", &n2,&rdummy1,&yScale,&rdummy2))
  748.     {
  749.     FileFormatError("ReadPBOLDfile", "error reading header line 3");
  750.     }
  751.     if (4 != fscanf(inFile, "%d %f %f %f\n", &n3,&rdummy1,&rdummy2,&zScale))
  752.     {
  753.     FileFormatError("ReadPBOLDfile", "error reading header line 4");
  754.     }
  755.     if (rdummy1 != 0.0 || rdummy2 != 0.0)
  756.     {
  757.     FileFormatError("ReadPBOLDfile", "warning: I don't understand files with weird orientations yet!");
  758.     }
  759.  
  760.     /* create a new Picture for the NFF stuff representing the atoms */
  761.     picture = NewPicture();
  762.  
  763.     /* read the atom position data */
  764.     for (i = 0; i < nAtoms; ++i)
  765.     {
  766.     float center[3];
  767.     int atomicNum;
  768.     float atomicCharge;
  769.     if (5 != fscanf(inFile, "%d %f %f %f %f\n", &atomicNum, &atomicCharge,
  770.                 &xLoc, &yLoc, &zLoc))
  771.     { 
  772.         sprintf(tempStr, "error reading atom %d\n", i);
  773.         FileFormatError("ReadPBOLDfile", tempStr);
  774.     }
  775.     center[0] = (xLoc - origin[0]) / xScale;
  776.     center[1] = (yLoc - origin[1]) / yScale;
  777.     center[2] = (zLoc - origin[2]) / zScale;
  778.     AppendSphereToPicture(picture, center, 1, -2);
  779.     }
  780.  
  781.     retPicture = NewObject(geometryClass,0);
  782.     SetVar(retPicture, DATA, picture);
  783.     SetVar(picture, REPOBJ, retPicture);
  784.     sprintf(tempStr, "%s%s", "atoms.", ShortNameOf(name));
  785.     SetVar(retPicture, NAME, NewString(tempStr));
  786.     RegisterDataset(retPicture);
  787.  
  788. #if 0
  789.     fprintf(stderr, "reading array of dimensions %d, %d, %d\n", n1, n2, n3);
  790. #endif
  791.  
  792.     /* create the data holder */
  793.     fieldData = NewRealArray(3, (long) n1, (long) n2, (long) n3);
  794.     dataPtr = ArrayMeat(fieldData);
  795.  
  796.     /* read the grid data */
  797.     notdone = true;
  798.     for (i=0; i<n1 && notdone; ++i)
  799.     {
  800.     for (j=0; j<n2 && notdone; ++j)
  801.     {
  802.         for (k=0; k<n3 && notdone; ++k)
  803.         {
  804.         real curVal;
  805.         if (1 != fscanf(inFile, "%g", &curVal))
  806.         {
  807.             sprintf(tempStr, "error reading array element %d %d %d\n", n1, n2, n3);
  808.             ReportError("ReadPBOLDFile", tempStr);
  809.             notdone = false;
  810.         }
  811.         *(dataPtr + i * n2 * n3 + j * n3 + k) = curVal;
  812.         }
  813.     }
  814.     }
  815.  
  816.     fclose(inFile);
  817.  
  818.     /*Create the data form*/
  819.     dataForm = NewObject(dataFormClass, 0);
  820.     dimsArray = NewRealArray(1, (long) 3);
  821.     
  822.     /*Put in some dimensions*/
  823.     dims[0] = n1;
  824.     dims[1] = n2;
  825.     dims[2] = n3;
  826.     CArray2Array(dimsArray, dims);
  827.     SetVar(dataForm, DIMENSIONS, dimsArray); 
  828.     boundsArray = NewRealArray(1, 6L);
  829.     bounds[0] = bounds[2] = bounds[4] = 0.0;
  830.     bounds[1] = n1;
  831.     bounds[3] = n2;
  832.     bounds[5] = n3;
  833.     CArray2Array(boundsArray, bounds);
  834.     SetVar(dataForm, BOUNDS, boundsArray);
  835.  
  836.     retField = NewObject(data3DScalar, 0);
  837.     SetVar(retField, DATA, fieldData);
  838.     SetVar(retField, DATAFORM, dataForm);
  839.     sprintf(tempStr, "%s%s", "charge.", ShortNameOf(name));
  840.     SetVar(retField, NAME, NewString(tempStr));
  841.  
  842.  
  843.     RegisterDataset(retField);
  844.     return NULLOBJ;
  845. }
  846.  
  847. ObjPtr ReadDAKFile(name)
  848. char *name;
  849. {
  850.     FILE *inFile;
  851.     Bool timeDep;
  852.     int ngrid, ach, time, nc, mc, ibtype[4]; /* parameters read from header*/
  853.     char *title;
  854.     ObjPtr tempData[7];
  855.     real *meatPtr[7];
  856.     ObjPtr tempDataset;
  857.     ObjPtr tempDataForm;
  858.     ObjPtr tempDimsArray;
  859.     real dims[2];
  860.     int i, j, k, l, m; /* misc. loop counters. */
  861.     real bounds[4];
  862.     ObjPtr boundsArray;
  863.     int result;
  864.  
  865.     inFile = fopen(name, "r");
  866.     if (!inFile)
  867.     {
  868.     Error("ReadDAKFile", OPENFILEERROR, name);
  869.     return NULLOBJ;
  870.     }
  871.  
  872.     tempStr[0] = 0;
  873.     if (NULL == fgets(tempStr, TEMPSTRSIZE, inFile))
  874.     {
  875.     FileFormatError("ReadDAKFile", "title not found");
  876.     return NULLOBJ;
  877.     }
  878.     if (strlen(tempStr) && tempStr[strlen(tempStr)-1] == '\n')
  879.     {
  880.     tempStr[strlen(tempStr)] = '\0';
  881.     printf("zapped the \n in the title\n");
  882.     }
  883.  
  884.     printf("strlen(tempStr) = %d\n", strlen(tempStr));
  885.  
  886.     title = Alloc(strlen(tempStr) + 1);
  887.     for (i=0; i<strlen(tempStr) + 1; ++i)
  888.     {
  889.     title[i] = '\0';
  890.     }
  891.     strncpy(title, tempStr, strlen(tempStr) + 1 < TEMPSTRSIZE ?
  892.                 strlen(tempStr) + 1 : TEMPSTRSIZE);
  893.  
  894.     if (1 != fscanf(inFile, "%d", &ngrid))
  895.     {
  896.     FileFormatError("ReadDAKFile", "error in header line");
  897.     Free(title);
  898.     return NULLOBJ;
  899.     }
  900.  
  901.  
  902.     fprintf(stderr, "title = %s, ngrid = %d\n", title, ngrid);
  903.  
  904.     for (i = 0; i<ngrid; ++i)
  905.     {
  906.     if (6 != (result = fscanf(inFile, "%d%d%d%d%d%d", &nc, &mc,
  907.             &(ibtype[0]), &(ibtype[1]), &(ibtype[2]), &(ibtype[3]))))
  908.     {
  909.         printf("result == %d\n", result);
  910.         FileFormatError("ReadDAKFile", "error reading section header");
  911.         Free(title);
  912.         return NULLOBJ;
  913.     }
  914.  
  915.     fprintf(stderr,"nc = %d, mc = %d, ibtype = %d, %d, %d, %d\n",
  916.         nc, mc, ibtype[0], ibtype[1], ibtype[2], ibtype[3]);
  917.  
  918.     dims[0] = mc;
  919.     dims[1] = nc;
  920.  
  921.     tempDataForm = NewObject(dataFormClass, 0);
  922.     tempDimsArray = NewRealArray(1, 2L);
  923.  
  924.     CArray2Array(tempDimsArray, dims);
  925.     SetVar(tempDataForm, DIMENSIONS, tempDimsArray);
  926.  
  927.     /*Put in the bounds*/
  928.     bounds[0] = 0.;
  929.     bounds[1] = mc - 1.0;
  930.     bounds[2] = 0.;
  931.     bounds[3] = nc - 1.0;
  932.     boundsArray = NewRealArray(1, 4L);
  933.     CArray2Array(boundsArray, bounds);
  934.     SetVar(tempDataForm, BOUNDS, boundsArray);
  935.  
  936.  
  937.     for (j=0; j<7; ++j)
  938.     {
  939.         tempData[j] = NewRealArray(2, (long) mc, (long) nc);
  940.         meatPtr[j] = ArrayMeat(tempData[j]);
  941.     }
  942.     for (k=0; k<mc; ++k)
  943.     {
  944.         for (l=0; l<nc; ++l)
  945.         {
  946.         for (m=0; m<7; ++m) /* seven sets of data interleaved */
  947.         {
  948.             int tmp1, tmp2;
  949.  
  950.             if (1 != fscanf(inFile,"%n%12f%n",&tmp1,meatPtr[m]++,&tmp2))
  951.             {
  952.             FileFormatError("ReadDAKFile", "error reading data");
  953.             return NULLOBJ;
  954.             }
  955.             if (tmp2-tmp1 > 14 || tmp2-tmp1 < 11)
  956.             {
  957.             printf("weird float read, tmp2 - tmp1 = %d\n", tmp2-tmp1);
  958.             }
  959.         }
  960.         }
  961.     }
  962.     for (j=0; j<7; ++j)
  963.     {
  964.         tempDataset = NewObject(data2DScalar, 0);
  965.         SetVar (tempDataset, DATA, tempData[j]);
  966.         SetVar (tempDataset, DATAFORM, tempDataForm);
  967.         sprintf(tempStr, "%s-%d-%d", ShortNameOf(name), i, j);
  968.         SetVar (tempDataset, NAME, NewString(tempStr));
  969.  
  970.         RegisterDataset(tempDataset);
  971.     }
  972.     }
  973.     return NULLOBJ;
  974. }
  975.  
  976. #define READONE(dataPtr)                        \
  977. {                                    \
  978.     int READtmp1, READtmp2;                        \
  979.                                     \
  980.     if (1 != fscanf(inFile,"%n%12f%n",&READtmp1,dataPtr,&READtmp2))    \
  981.     {                                    \
  982.     FileFormatError("ReadDAKNEWFile", "error reading data");    \
  983.     return NULLOBJ;                            \
  984.     }                                    \
  985.     if (READtmp2-READtmp1 > 14 || READtmp2-READtmp1 < 11)        \
  986.     {                                    \
  987.     FileFormatError("ReadDAKNEWFile", "confused data format?");    \
  988.     return NULLOBJ;                            \
  989.     }                                    \
  990. }
  991.  
  992. ObjPtr ReadDAKNEWFile(name)
  993. char *name;
  994. {
  995.     FILE *inFile;
  996.     Bool timeDep;
  997.     int ngrid, ach, time, nc, mc, ibtype[4]; /* parameters read from header*/
  998.     char *title;
  999.     ObjPtr tempData[7];
  1000.     real *meatPtr[7];
  1001.     ObjPtr tempDataset;
  1002.     ObjPtr tempDataForm;
  1003.     ObjPtr tempDimsArray;
  1004.     ObjPtr tempGrid,tempGrid2;
  1005.     ObjPtr tempGridData,tempGridData2;
  1006.     long int rank;
  1007.     real dims[2];
  1008.     long index[2];
  1009.     int i, j, k, l, m; /* misc. loop counters. */
  1010.     real bounds[4];
  1011.     ObjPtr boundsArray;
  1012.     int result;
  1013.     real dummy;
  1014.  
  1015.     inFile = fopen(name, "r");
  1016.     if (!inFile)
  1017.     {
  1018.     Error("ReadDAKFile", OPENFILEERROR, name);
  1019.     return NULLOBJ;
  1020.     }
  1021.  
  1022.     tempStr[0] = 0;
  1023.     if (NULL == fgets(tempStr, TEMPSTRSIZE, inFile))
  1024.     {
  1025.     FileFormatError("ReadDAKNEWFile", "title not found");
  1026.     return NULLOBJ;
  1027.     }
  1028.     if (strlen(tempStr) && tempStr[strlen(tempStr)-1] == '\n')
  1029.     {
  1030.     tempStr[strlen(tempStr)] = '\0';
  1031.     printf("zapped the \n in the title\n");
  1032.     }
  1033.  
  1034.     printf("strlen(tempStr) = %d\n", strlen(tempStr));
  1035.  
  1036.     title = Alloc(strlen(tempStr) + 1);
  1037.     for (i=0; i<strlen(tempStr) + 1; ++i)
  1038.     {
  1039.     title[i] = '\0';
  1040.     }
  1041.     strncpy(title, tempStr, strlen(tempStr) + 1 < TEMPSTRSIZE ?
  1042.                 strlen(tempStr) + 1 : TEMPSTRSIZE);
  1043.  
  1044.     if (1 != fscanf(inFile, "%d", &ngrid))
  1045.     {
  1046.     FileFormatError("ReadDAKNEWFile", "error in header line");
  1047.     Free(title);
  1048.     return NULLOBJ;
  1049.     }
  1050.  
  1051.  
  1052.     fprintf(stderr, "title = %s, ngrid = %d\n", title, ngrid);
  1053.  
  1054.     for (i = 0; i<ngrid; ++i)
  1055.     {
  1056.     float gridXMin, gridXMax, gridYMin, gridYMax;
  1057.     if (6 != (result = fscanf(inFile, "%d%d%d%d%d%d", &nc, &mc,
  1058.             &(ibtype[0]), &(ibtype[1]), &(ibtype[2]), &(ibtype[3]))))
  1059.     {
  1060.         printf("result == %d\n", result);
  1061.         FileFormatError("ReadDAKNEWFile", "error reading section header");
  1062.         Free(title);
  1063.         return NULLOBJ;
  1064.     }
  1065.  
  1066.     fprintf(stderr,"nc = %d, mc = %d, ibtype = %d, %d, %d, %d\n",
  1067.         nc, mc, ibtype[0], ibtype[1], ibtype[2], ibtype[3]);
  1068.  
  1069.     /* file fields 0 and 1 ignored, presently */
  1070.     /* Create holders for file fields 2, 5, 6 */
  1071.     for (j=0; j<5; ++j)
  1072.     {
  1073.         tempData[j] = NewRealArray(2, (long) mc, (long) nc);
  1074.         meatPtr[j] = ArrayMeat(tempData[j]);
  1075.     }
  1076.     /* Create holder for 2d vector field (formed by file fields 0, 1)*/
  1077.     tempGrid = NewObject(datasetClass, 0);
  1078.     SetVar(tempGrid, DEFAULTICON, icon2DVector);
  1079.     SetVar(tempGrid, NCOMPONENTS, NewInt(2));
  1080.     rank = 2;
  1081.     tempGridData = SetVar(tempGrid, DATA, NewArray(AT_OBJECT, 1, &rank));
  1082.     for (k = 0; k < rank; ++k)
  1083.     {
  1084.         ((ObjPtr *) ELEMENTS(tempGridData))[k] = NewRealArray(2, (long) mc, (long) nc);
  1085.     }
  1086.     if (!SetCurField(FIELD1, tempGrid)) return NULLOBJ;
  1087.  
  1088.     /* Create another vecotr field which double-defines  */
  1089.     tempGrid2 = NewObject(datasetClass, 0);
  1090.     SetVar(tempGrid2, DEFAULTICON, icon2DVector);
  1091.     SetVar(tempGrid2, NCOMPONENTS, NewInt(2));
  1092.     tempGridData2 = SetVar(tempGrid2, DATA, NewArray(AT_OBJECT, 1, &rank));
  1093.     ((ObjPtr *) ELEMENTS(tempGridData2))[0] = tempData[3];
  1094.     ((ObjPtr *) ELEMENTS(tempGridData2))[1] = tempData[4];
  1095.  
  1096.     gridXMin = gridYMin = PLUSINF;
  1097.     gridXMax = gridYMax = MINUSINF;
  1098.  
  1099.     for (index[0]=0; index[0]<mc; ++index[0])
  1100.     {
  1101.         for (index[1]=0; index[1]<nc; ++index[1])
  1102.         {
  1103.         /* seven sets of data interleaved */
  1104.  
  1105. #define FOOBARSCALE 10.0
  1106.  
  1107.         /* file fields 0 and 1 form 2D vector dataset */
  1108.         READONE(&dummy);
  1109.         dummy *= FOOBARSCALE;
  1110.         PutFieldComponent(FIELD1, 0, index, dummy);
  1111.         if (gridXMin > dummy)
  1112.             gridXMin = dummy;
  1113.         if (gridXMax < dummy)
  1114.             gridXMax = dummy;
  1115.         READONE(&dummy)
  1116.         dummy *= FOOBARSCALE;
  1117.         PutFieldComponent(FIELD1, 1, index, dummy);
  1118.         if (gridYMin > dummy)
  1119.             gridYMin = dummy;
  1120.         if (gridYMax < dummy)
  1121.             gridYMax = dummy;
  1122.  
  1123.         /* file field 2 to scalar dataset 0 */
  1124.         READONE(meatPtr[0]);
  1125.         ++meatPtr[0];
  1126.  
  1127.         /* file fields 3 and 4 ignored */
  1128.         /* temporarily viewed as 2 separate scalars */
  1129.         READONE(meatPtr[3]);
  1130.         ++meatPtr[3];
  1131.         READONE(meatPtr[4]);
  1132.         ++meatPtr[4];
  1133.  
  1134.         /* file fields 5 and 6 to scalar datasets 1 and 2 */
  1135.         READONE(meatPtr[1]);
  1136.         ++meatPtr[1];
  1137.         READONE(meatPtr[2]);
  1138.         ++meatPtr[2];
  1139.         }
  1140.     }
  1141.  
  1142.     dims[0] = mc;
  1143.     dims[1] = nc;
  1144.  
  1145.     tempDataForm = NewObject(dataFormClass, 0);
  1146.     tempDimsArray = NewRealArray(1, 2L);
  1147.  
  1148.     CArray2Array(tempDimsArray, dims);
  1149.     SetVar(tempDataForm, DIMENSIONS, tempDimsArray);
  1150.  
  1151.     /*Put in the bounds*/
  1152.     bounds[0] = gridXMin;
  1153.     bounds[1] = gridXMax;
  1154.     bounds[2] = gridYMin;
  1155.     bounds[3] = gridYMax;
  1156.     boundsArray = NewRealArray(1, 4L);
  1157.     CArray2Array(boundsArray, bounds);
  1158.     SetVar(tempDataForm, BOUNDS, boundsArray);
  1159.  
  1160.     /* hold our nose and dive in, hoping this grid stuff works */
  1161.     SetVar(tempDataForm, DATA, tempGrid);
  1162.  
  1163.     /* finish up and Register the scalar fields */
  1164.     for (j=0; j<5; ++j)
  1165.     {
  1166.         tempDataset = NewObject(data2DScalar, 0);
  1167.         SetVar (tempDataset, DATA, tempData[j]);
  1168.         SetVar (tempDataset, DATAFORM, tempDataForm);
  1169.         if (j < 3)
  1170.         sprintf(tempStr, "%s-%d-scalar%d", ShortNameOf(name), i, j);
  1171.         else
  1172.         sprintf(tempStr, "%s-%d-vcomp%d", ShortNameOf(name), i, j-3);
  1173.         SetVar (tempDataset, NAME, NewString(tempStr));
  1174.         RegisterDataset(tempDataset);
  1175.  
  1176.     }
  1177.     /* Register the vector field */
  1178.     sprintf(tempStr, "%s-%d-vector", ShortNameOf(name), i);
  1179.     SetVar (tempGrid2, NAME, NewString(tempStr));
  1180.     SetVar (tempGrid2, DATAFORM, tempDataForm);
  1181.     RegisterDataset(tempGrid2);
  1182.     }
  1183.     return NULLOBJ;
  1184. }
  1185.  
  1186. void InitJohnFiles()
  1187. {
  1188. #ifndef RELEASE
  1189.     DefineFormat("GBC", "", ReadGBCFile, 0);
  1190.     DefineFormat("GBC2", "", ReadGBC2File, 0);
  1191.     DefineFormat("SS", "", ReadSSFile, 0);
  1192.     DefineFormat("PB", "pb", ReadG90File, 0);
  1193. #endif
  1194.     DefineFormat("G90", "g90", ReadG90File, 0);
  1195. /*    DefineFormat("PBOLD", "", ReadPBOLDFile, 0);
  1196. */
  1197.     DefineFormat("DAK", "fplt", ReadDAKNEWFile, 0);
  1198. }
  1199.  
  1200. void KillJohnFiles()
  1201. {
  1202. }
  1203.